package euler.p001_050;

import euler.MainEuler;

public class Euler009 extends MainEuler {
    /*
        A Pythagorean triplet is a set of three natural numbers,
        a < b < c, for which, a^2 + b^2 = c^2

        For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.

        There exists exactly one Pythagorean triplet for which a + b + c = 1000.
        Find the product abc.

     */
    public String resolve() {
        int n = 0;
        int suma = 1000;

        for (int a = 1; (n == 0) && (2*a < (suma - 1)); a++) {
            for (int b = a + 1; (n == 0) && (2*b < (suma - a)); b++) {
                int c = suma - a - b;
                if (c*c == a*a + b*b) {
                    n = a*b*c;
                }
            }
        }

        return String.valueOf(n);
    }
}
